﻿using Bids.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.OpenAccess;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;

namespace Bids.Core.DomainObjects
{
	/// <summary>
	/// 财务明细
	/// </summary>
	[Serializable]
	public class Finance : IEntity
	{
       
		/// <summary>
		/// 
		/// </summary>
        public virtual int ID { set;  get; }
		/// <summary>
		/// 用户id
		/// </summary>
        public virtual int UserId { set; get; }
		/// <summary>
		/// 明细金额
		/// </summary>
        public virtual int Amount { set; get; }
		/// <summary>
		/// 进出帐标志
		/// </summary>
        public virtual int Type { set; get; }
		/// <summary>
		/// 明细产生时间
		/// </summary>
        public virtual DateTime CreateTime { set; get; }
		/// <summary>
		/// 状态
		/// </summary>
        public virtual int State { set; get; }
        /// <summary>
        /// 备注
        /// </summary>
        public virtual string Remark { get; set; }

        public virtual User User { get; set; }
        public virtual FinanceType FinanceType
        {
            get {
                return (DomainObjects.FinanceType)this.Type;
            }
        }
        public virtual FinanceStatus FinanceState
        {
            get
            {
                return (DomainObjects.FinanceStatus)this.State;
            }
        }

        public static MappingConfiguration<Finance> CreateConfiguration()
        {
            var threadMapping = new MappingConfiguration<Finance>();
            threadMapping.MapType(t => new
            {
                t.ID,
                t.UserId,
                t.Type,
                t.State,
                t.Amount,
                t.CreateTime,
                t.Remark
            }).ToTable("Finances");
            threadMapping.HasProperty(t => t.ID).IsIdentity(KeyGenerator.Autoinc);
            threadMapping.HasAssociation(t => t.User).WithOpposite(d => d.Finances).HasConstraint((t, d) => t.UserId == d.ID);
            return threadMapping;
        }
	}
    public enum FinanceType
    {
        收入 = 1,
        支出 = 2
    }
    public enum FinanceStatus
    { 
        审核 = 1,
        完成 = 2,
        取消 = 3
    }
}

